import { WALL, MOVE_1, MOVE_2 } from './constant';
export default {
  methods: {
    // 前方一格的位置是墙
    haveWall1(dir) {
      let move = MOVE_1[dir];
      let next = [this.position[0] + move[0], this.position[1] + move[1]];
      return this.map[next[0]][next[1]] === WALL;
    },
    // 前方两格的位置是墙
    haveWall2(dir) {
      let move = MOVE_2[dir];
      let next = [this.position[0] + move[0], this.position[1] + move[1]];
      return this.map[next[0]][next[1]] === WALL;
    },
    // 前方一格的位置是箱子
    haveBox1(dir) {
      let move = MOVE_1[dir];
      let next = [this.position[0] + move[0], this.position[1] + move[1]];
      let box = this.boxes.find((box) => {
        return box.position[0] === next[0] && box.position[1] === next[1];
      });
      return !!box; // this.map[next[0]][next[1]] === WALL;
    },
    // 前方两格的位置是箱子
    haveBox2(dir) {
      let move = MOVE_2[dir];
      let next = [this.position[0] + move[0], this.position[1] + move[1]];
      let box = this.boxes.find((box) => {
        return box.position[0] === next[0] && box.position[1] === next[1];
      });
      return !!box;
    }
  }
};
